<!-- 布卷列表 -->
<template>
	<view class="ku-content">
		<view class="ku-section" v-if="shippingInfo">
			<view class="">
				<u-row justify="space-between" gutter="10">
					<u-col span="6">
						<u-button text="月落" shape='circle' :plain="true"
							class="ku-text-bold">{{shippingInfo.beequalto}}匹</u-button>
					</u-col>
					<u-col span="6">
						<u-button text="月落" shape='circle' :plain="true"
							class="ku-text-bold">{{shippingInfo.meters}}米</u-button>
					</u-col>
				</u-row>
			</view>
			<view class="ku-margin-top-30 ku-swipe-content">
				<u-swipe-action>
					<u-swipe-action-item :options="actionOptions" v-for="(item,index) in clothRollList" :key="index"
						:name='index' @click="clickAction">

						<view class="ku-card">
							<view class="ku-subtitle">
								{{item.fnumber}}【{{item.fname}}】
							</view>
							<view class="">
								<u-row justify="space-between" gutter="10">
									<u-col span="6">
										<view class="ku-mi-title">布卷类型:
											<template v-if="item.f_ryjf_bjlx==='0'">胚布</template>
											<template v-if="item.f_ryjf_bjlx==='1'">成品</template>
											<template v-if="item.f_ryjf_bjlx==='2'">半成品</template>
											/{{item.bjdj}}
										</view>

									</u-col>
									<u-col span="6">
										<view class="ku-mi-title">{{item.f_ryjf_mis}}米 / {{item.f_ryjf_mas}}码</view>
									</u-col>
								</u-row>
							</view>
						</view>
					</u-swipe-action-item>
				</u-swipe-action>
			</view>
		</view>
	</view>
</template>

<script>
	import store from "@/store";
	import {
		getSalesOutboundInfo,
		operationSalesOutboundOrder
	} from "@/api/index.js";

	export default {
		data() {
			return {
				urlParams:'',
				shippingInfo: {},
				fnumber: '',
				clothRollList: [], // 布卷列表
				actionOptions: [{
					text: '删除',
					style: {
						backgroundColor: '#f56c6c'
					}
				}],
				deleteOperationObject: '', // 要删除的布卷信息
			};
		},

		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad(options) {
			// 当前页面参数
			console.log('布卷列表--options----2-->', options);
			this.urlParams = options;
		},

		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow(options) {
			this.getSalesOutboundInfoFun();
		},
		/**
		 * 生命周期函数--监听页面显示
		 */
		methods: {
			// 获取布卷列表
			getSalesOutboundInfoFun() {
				let params = {
					fid: this.urlParams.fid,
				};

				getSalesOutboundInfo(params).then((res) => {
					console.log('获取布卷列表---res-->', res)
					if (res.code === 200 && res.datas && res.datas.length > 0) {
						this.shippingInfo = res.datas[0]
						this.clothRollList = res.datas[0].datas || [];
					} else {
						console.log('获取布卷列表---res-->', res)
						// uni.showToast({
						// 	title: "用户或密码有误",
						// 	icon: "none",
						// 	duration: 2000,
						// });
					}
				})
			},


			// 活动操作
			clickAction(e) {
				console.log('活动操作-----》', e);
				let deleteOperationObject = this.clothRollList[e.name]
				this.operationSalesOutboundOrderFun(deleteOperationObject)

			},

			// 销售出库单保存、删除
			operationSalesOutboundOrderFun(parameters) {
				console.log('销售出库单删除-----params-->', parameters)
				let params = {
					xsckFid: this.shippingInfo.fid,
					code: 1, // 状态，0-保存，1-删除
					ckid: this.shippingInfo.ckid, // 仓库id
					cwid: this.shippingInfo.cwid, // 仓位id
					colorid: this.shippingInfo.colorid, // 颜色
					sizeid: this.shippingInfo.sizeid, // 尺码
					doorwidthid: this.shippingInfo.doorwidthid, // 门幅

					clothRolls: [{
						...parameters
					}]
				};
				console.log('销售出库单保存-----params-->', params)
				operationSalesOutboundOrder(params).then((res) => {
					console.log('销售出库单保存-----res-->', res)
					if (res.code === 200) {
						this.getSalesOutboundInfoFun();
					} else {
						console.error('根据布卷单据编号获取布卷信息---error-->', res)
						// uni.showToast({
						// 	title: "用户或密码有误",
						// 	icon: "none",
						// 	duration: 2000,
						// });
					}
				})
			},

		}
	}
</script>

<style lang="scss">

</style>